USE [BMIG_Mensual_POST_CADENA]
GO

/****** Object:  StoredProcedure [dbo].[WASP_M0003_CODIGOS_SEGUROS]    Script Date: 11/28/2011 12:08:17 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[WASP_M0003_CODIGOS_SEGUROS]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[WASP_M0003_CODIGOS_SEGUROS]
GO

USE [BMIG_Mensual_POST_CADENA]
GO

/****** Object:  StoredProcedure [dbo].[WASP_M0003_CODIGOS_SEGUROS]    Script Date: 11/28/2011 12:08:17 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[WASP_M0003_CODIGOS_SEGUROS]
AS

BEGIN
	SELECT a.ppcta, a.ppoper, a.ppsuc, 
		   a.ppimp11, a.ppimp12, a.ppimp13, a.ppimp14, a.ppimp15,
		   a.ppimp16, a.ppimp17, a.ppimp18, a.ppimp19

	INTO
		dbo.prima_comision_codigos_seguros

	FROM fsd611 as a (nolock),
		 fsd601 as b  (nolock) 

	WHERE--a.ppoper = 100000109 and
		 -- a.ppsuc = 11 and
			a.pptipo = '' and a.ppexte = 9 and
			a.ppsbop = 0 and 
			a.pgcod = b.pgcod and
			a.ppmod = b.ppmod and
			a.ppsuc = b.ppsuc and 
			a.ppmda = b.ppmda and
			a.ppcta = b.ppcta and 
			a.ppoper = b.ppoper and
			a.ppsbop = b.ppsbop and
			a.pptope = b.pptope and
			b.d601co = 'S'

	GROUP BY a.ppsuc, a.ppcta, a.ppoper, a.ppimp11, a.ppimp12,
			 a.ppimp13, a.ppimp14, a.ppimp15, a.ppimp16,
			 a.ppimp17, a.ppimp18, a.ppimp19
END
GO

